<?php
echo 'query string:' . $_SERVER["QUERY_STRING"];
echo "<br>\r\n";
echo 'user name:' . $_GET["username"];
echo "<br>\r\n";
echo 'computer id:' . $_GET["computerid"];
echo "<br>\r\n";
echo 'file name:' . $_GET["filename"];
echo "<br>\r\n";

if (getenv("REQUEST_METHOD") == 'PUT') {
// write the input stream into file
$finput = fopen("php://input", "rb");
$folder = '/tmp/users/' . $_GET["username"] . '/' . $_GET["computerid"] . '/files/';
if (!(file_exists($folder) && is_dir($folder)))
{
   mkdir($folder, 0766, true);
}

$fstorage = fopen($folder . $_GET["filename"], 'wb');

while (!feof($finput)) {
  $buf = fread($finput, 4096);
  fwrite($fstorage, $buf);
}
fclose($finput);
fclose($fstorage);
echo 'md5:' . md5_file($folder . $_GET["filename"]);
}

?>


